import {NestFactory} from '@nestjs/core';
import {AppModule} from './app.module';
import {NestExpressApplication} from "@nestjs/platform-express";
import * as path from "path";
import * as cookieParser from "cookie-parser";
import * as session from "express-session";

async function bootstrap() {
    // 创建 NestJS 应用实例，并指定基于 Express 平台
    const app = await NestFactory.create<NestExpressApplication>(AppModule);

    // 静态资源目录配置
    app.useStaticAssets(path.join(__dirname, '..', 'public'), {
        prefix: '/static/' // 为静态资源文件添加一个虚拟路径前缀，可选
    });
    // 配置模板引擎
    app.setBaseViewsDir('views');
    app.setViewEngine('ejs');

    // 配置Cookie、Session
    app.use(cookieParser('CF8136B13D46495CA6AFF3297FD4D8FC'))
    app.use(session({
        secret: 'B125C1B83DEAB9B667E571489421CB71',
        resave: false,
        saveUninitialized: false,
        cookie: {maxAge: 3600000, httpOnly: true},
        rolling: false
    }))

    await app.listen(3000);
}

bootstrap();
